package com.sgcc.fj.pmos.e_fj_mall.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.sgcc.fj.pmos.common.bean.StoreInfoBean;
import com.sgcc.fj.pmos.common.http.HttpInterConst;
import com.sgcc.fj.pmos.common.utils.BigDecimalUtils;
import com.sgcc.pmos.nativesdk.R;

import java.math.BigDecimal;

public class StoreAdapter extends BaseQuickAdapter<StoreInfoBean, BaseViewHolder> {

    private Context mContext;

    public StoreAdapter(Context context) {
        super(R.layout.item_store_fj);
        mContext = context;
    }

    public interface OnItemClickListener {
        //条目点击
        void itemClickListener(int position, StoreInfoBean s);
    }

    private OnItemClickListener mOnItemClickListener;

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.mOnItemClickListener = onItemClickListener;
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, StoreInfoBean bean) {
        String img_url = HttpInterConst.BASEURL_IMG + bean.getFileId();
        ImageView imageView = baseViewHolder.getView(R.id.iv_company_logo);
        Glide.with(mContext).load(img_url).placeholder(R.mipmap.deft_merchant).error(R.mipmap.deft_merchant).into(imageView);

        baseViewHolder.setText(R.id.tv_company_name, bean.getMembersSdName());
        baseViewHolder.setText(R.id.tv_credit_rating, TextUtils.isEmpty(bean.getCreditRating()) ? "——" : bean.getCreditRating());
        baseViewHolder.setText(R.id.tv_enterprise_nature, bean.getTcCount() + "个");

        String saleEnergy = BigDecimalUtils.onKeep3Decimal(bean.getSaleEnergy());
        BigDecimal kysEnergy_b = new BigDecimal(saleEnergy);
        int i = kysEnergy_b.compareTo(BigDecimal.ZERO);
        String result = "";
        if (i == -1) {
            result = "不限量";
        } else {
            result = saleEnergy;
        }

        baseViewHolder.setText(R.id.tv_kxs_electricity, "0.000".equals(result) ? "0" : result);
        String bys = BigDecimalUtils.onKeep3Decimal(bean.getYearSaleEnergy());
        baseViewHolder.setText(R.id.tv_bys_electricity, "0.000".equals(bys) ? "0" : bys);

        baseViewHolder.getView(R.id.rl_store).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mOnItemClickListener != null) {
                    mOnItemClickListener.itemClickListener(getItemPosition(bean), bean);
                }
            }
        });
    }

}
